﻿/*文件注释
 * ===============================================================================
 * 说明：
 * 作者：曾永佑
 * 版本：v1.0
 * 创建日期：2013-11-1
 * 完成日期： 
 * 修改纪录：  
 * ===============================================================================
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SRF.Common.Logging
{
    /// <summary>
    /// 
    /// </summary>
    public sealed class LogManager
    {
        /// <summary>
        /// get logger by current class type
        /// </summary>
        /// <returns></returns>
        public static ILog GetCurrentLogger()
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, false);
            if (stackFrame.GetMethod() != null && stackFrame.GetMethod().DeclaringType != null)
                return GetLogger(stackFrame.GetMethod().DeclaringType.Name);
            else
                return GetLogger(typeof(LogManager).Name);
        }
        /// <summary>
        /// get logger by type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ILog GetLogger(Type type)
        {
            return GetLogger(type.Name);
        }
        /// <summary>
        /// get logger by name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ILog GetLogger(string name)
        {
            ILogFactory logFactory = ObjectHelper.GetObject<ILogFactory, Impl.Log4Factory>();
            if (logFactory == null)
                return null;
            else
                return logFactory.GetLogger(name);
        }
    }
}